import { GlobalData } from '/store/state'
import { $event } from '/utils'

Component({
  /**
   * Component properties
   */
  properties: {},

  /**
   * Component initial data [private]
   */
  data: {
    show: GlobalData.vote,
    vote: false,
    res: {} as GetRewardMessageReturns,
    currencyName: GlobalData.currencyName,
  },

  /**
   * lifecycle of component
   */
  pageLifetimes: {
    show() {
      console.log(GlobalData.vote)
      $event.on('showMessage', this, (res: GetRewardMessageReturns) => {
        this.onShow(res)
      })
      $event.on('after:boot', this, () => {
        this.setData({ currencyName: GlobalData.currencyName })
      })
    },
  },

  /**
   * Component methods
   */
  methods: {
    onShow(res: GetRewardMessageReturns) {
      this.setData({ show: true, loading: true, res })
      setTimeout(() => {
        this.setData({ show: false })
      }, 200000)
    },
    onClose() {
      this.setData({ show: false })
      clearTimeout
    },
  },
})
